﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TableParsers;

namespace Speakup
{
    public struct WeekThemeKey: IEquatable<WeekThemeKey>, IComparable, IComparable<WeekThemeKey>
    {
        public ThemeLevel Level { get; private set; }
        public ClassType ClassType { get; private set; }
        public int Week { get; private set; }

        public WeekThemeKey(ClassType classType, ThemeLevel level, int week): this()
        {
            Level = level;
            ClassType = classType;
            Week = week;
        }

        public override bool Equals(object obj)
        {
            WeekThemeKey? rhs = obj as WeekThemeKey?;
            if (rhs == null) return false;
            return base.Equals(obj);
        }
        public bool Equals(WeekThemeKey rhs)
        {
            if (ReferenceEquals(rhs, this))
                return true;

            return ClassType == rhs.ClassType &&
                   Level     == rhs.Level &&                   
                   Week      == rhs.Week;
        }

        public override int GetHashCode()
        {
            int hash = 13;
            unchecked
            {
                hash = (hash * 397) + Level.GetHashCode();
                hash = (hash * 397) + ClassType.GetHashCode();
                hash = (hash * 397) + Week.GetHashCode();                
            }
            return hash;
        }
        public int CompareTo(object rhs)
        {
            return CompareTo((WeekThemeKey)rhs);
        }
        public int CompareTo(WeekThemeKey rhs)
        {
            if (ClassType != rhs.ClassType)
            {
                return ClassType.CompareTo(rhs.ClassType);
            }

            if (Level != rhs.Level)
            {
                return Level.CompareTo(rhs.Level);
            }

            return Week.CompareTo(rhs.Week);
        }

        public static bool operator ==(WeekThemeKey lhs, WeekThemeKey rhs)
        {
            return lhs.Equals(rhs);
        }
        public static bool operator !=(WeekThemeKey lhs, WeekThemeKey rhs)
        {
            return !lhs.Equals(rhs);
        }

        public override String ToString()
        {
            return string.Format("[{0}, Level {1}, Week {2:00}]", 
                                 ClassType.ToString(), Level.ToString(), Week);
        }
    }
}
